package co.chuangdian.oflauncher;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.TextView;
import cn.onekit.APP;
import cn.onekit.CALLBACK;
import cn.onekit.CONFIG;
import cn.onekit.FSO;
import cn.onekit.JSON;
import co.chuangdian.oflauncher.R;

import uc.allapp.AllAppActivity;

public class LockScreenActivity extends OFActivity {
	
	JSONArray fastAppIDs = new JSONArray();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lockscreen);
	

	
	
		loadData();
	}

	GestureDetector mGesture;

	public class GestureListener extends SimpleOnGestureListener {

		@Override
		public boolean onDoubleTap(MotionEvent e) {
			return super.onDoubleTap(e);
		}

		@Override
		public boolean onDown(MotionEvent e) {
			return super.onDown(e);
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
			finish();
			return super.onFling(e1, e2, velocityX, velocityY);
		}

		@Override
		public void onLongPress(MotionEvent e) {
			super.onLongPress(e);
		
		}

		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
			return super.onScroll(e1, e2, distanceX, distanceY);
		}

		@Override
		public boolean onSingleTapUp(MotionEvent e) {
			return super.onSingleTapUp(e);
		}

	}

	@SuppressWarnings("deprecation")
	@SuppressLint("SimpleDateFormat")
	void loadData() {
		JSONObject lockscreen = JSON.parse(CONFIG.get("lockscreen"));

		File path = FSO.photos(lockscreen.optString("cover"));
		Bitmap cover = FSO.loadImage(path.getPath(), false);
		((ImageView) this.findViewById(R.id.coverImageView)).setImageBitmap(cover);
		//
		Calendar calendar = Calendar.getInstance();
		int day = calendar.get(Calendar.DAY_OF_WEEK);
		String today;
		if (day == 2) {
			today = "星期一";
		} else if (day == 3) {
			today = "星期二";
		} else if (day == 4) {
			today = "星期三";
		} else if (day == 5) {
			today = "星期四";
		} else if (day == 6) {
			today = "星期五";
		} else if (day == 7) {
			today = "星期六";
		} else if (day == 1) {
			today = "星期天";
		} else {
			today = "";
		}
		((TextView) this.findViewById(R.id.timeTextView)).setText(new SimpleDateFormat("HH:mm").format(new Date()));
		//
		((TextView) this.findViewById(R.id.dateTextView))
				.setText(new SimpleDateFormat("MM月dd日 ").format(new Date()) + today);
		//
		JSONArray apps = lockscreen.optJSONArray("apps");
		List<Drawable> fastAppIcons = new ArrayList<Drawable>();
		PackageManager packageManager = getPackageManager();
		for (int i = 0; i < apps.length(); i++) {
			Drawable icon;
			try {
				icon = packageManager.getApplicationIcon(apps.optString(i));
				fastAppIcons.add(icon);
			} catch (NameNotFoundException e) {
				e.printStackTrace();
			}
		}
		fastAppIcons.add(getResources().getDrawable(R.drawable.ic_launcher));
		fastAppIcons.add(getResources().getDrawable(R.drawable.ic_launcher));
		fastAppIcons.add(getResources().getDrawable(R.drawable.ic_launcher));
		fastAppIcons.add(getResources().getDrawable(R.drawable.ic_launcher));
		fastAppIcons.add(getResources().getDrawable(R.drawable.ic_launcher));
	

	
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			return true;
		default:
			break;
		}
		return super.onKeyDown(keyCode, event);
	}
}
